package tech.aistar.service.position.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tech.aistar.entity.Area;
import tech.aistar.entity.City;
import tech.aistar.entity.Province;
import tech.aistar.mapper.position.AreaMapper;
import tech.aistar.mapper.position.CityMapper;
import tech.aistar.mapper.position.ProvinceMapper;
import tech.aistar.service.position.IAreaService;
import tech.aistar.vo.ProvinceCityAreaQueryVo;

import java.util.List;

/**
 * @Author: lya
 * @Description: 本类的作用描述:
 * @CreateDate: 2019/10/3
 * @Version: 1.0
 */
@Service
public class AreaServiceImpl implements IAreaService {
    @Autowired
    private AreaMapper areaMapper;
    @Autowired
    private CityMapper cityMapper;
    @Autowired
    private ProvinceMapper provinceMapper;

    @Override
    public List<Area> findAll() {
        List<Area> list = areaMapper.findAll();
        return list;
    }

    @Override
    public Area findById(Integer id) {
        Area area = areaMapper.findById(id);
        return area;
    }

    /**
     * 通过区ID查询省市区
     */
    @Override
    public ProvinceCityAreaQueryVo selectPCA(Integer id) {
        ProvinceCityAreaQueryVo pca = new ProvinceCityAreaQueryVo();
        Area area = areaMapper.findById(id);
        City city = cityMapper.findById(area.getCode());
        Province province = provinceMapper.findById(city.getProvinceId());
        pca.setId(area.getId());
        pca.setaName(area.getName());
        pca.setCityId(city.getId());
        pca.setcName(city.getName());
        pca.setProvinceId(province.getId());
        pca.setpName(province.getName());
        return pca;
    }
}
